using System;
using System.Diagnostics;
using PugLib;

namespace ParallelTest
{
    public partial class Benchmarks
    {
        public const Int64 StackAssertValue = 13500;

        #region Stack/Heap

        public static TestResult AddStaticStart()
        {
            Console.WriteLine("AddStaticStart");
            TestResult trd = new TestResult("AddStaticStart");
            Int64 total = 0;
            stopwatch.Reset();
            stopwatch.Start();
            while (total < StackAssertValue)
            {
                total++;
            }
            stopwatch.Stop();
            trd.Duration = stopwatch.Elapsed.TotalSeconds;
            Debug.Assert(total == StackAssertValue);
            return trd;
        }

        public static TestResult AddStaticRecursiveStart()
        {
            Console.WriteLine("AddStaticRecursiveStart");
            TestResult trd = new TestResult("AddStaticRecursiveStart");
            Int64 total = 0;
            stopwatch.Reset();
            stopwatch.Start();
            AddStaticRecursive(ref total);
            stopwatch.Stop();
            trd.Duration = stopwatch.Elapsed.TotalSeconds;
            Debug.Assert(total == StackAssertValue);
            return trd;
        }

        public static TestResult AddRecursiveStart()
        {
            Console.WriteLine("AdRecursiveStart");
            TestResult trd = new TestResult("AdRecursiveStart");
            Benchmarks b = new Benchmarks();
            Int64 total = 0;
            stopwatch.Reset();
            stopwatch.Start();
            b.AddRecursive(ref total);
            stopwatch.Stop();
            trd.Duration = stopwatch.Elapsed.TotalSeconds;
            Debug.Assert(total == StackAssertValue);
            return trd;
        }

        public void AddRecursive(ref Int64 value)
        {
            if (value < StackAssertValue)
            {
                value++;
                AddRecursive(ref value);
            }
        }

        public static void AddStaticRecursive(ref Int64 value)
        {
            if (value < StackAssertValue)
            {
                value++;
                AddStaticRecursive(ref value);
            }
        }

        #endregion


    }
}
